package com.friend.controller.user;

import com.api.domain.vo.UserQuestionResultVO;
import com.common.core.controller.BaseController;
import com.common.core.domain.Result;
import com.friend.domain.user.dto.UserSubmitDTO;
import com.friend.service.question.UserQuestionService;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/user/question")
@Tag(name = "用户与题目管理API")
public class UserQuestionController extends BaseController {

    @Resource
    UserQuestionService userQuestionService;

    /**
     * 提交代码
     *
     */
    @PostMapping("/submit")
    public Result<UserQuestionResultVO> submit(@RequestBody UserSubmitDTO userSubmitDTO){
        return userQuestionService.submit(userSubmitDTO);
    }

    /**
     * 提交代码（使用RabbitMQ）
     *
     */
    @PostMapping("/rabbit/submit")
    public Result<Void> rabbitSubmit(@RequestBody UserSubmitDTO userSubmitDTO){
        return toResult(userQuestionService.rabbitSubmit(userSubmitDTO));
    }

    /**
     * 获取提交代码的结果
     *
     */
    @GetMapping("/exe/result")
    public Result<UserQuestionResultVO> exeResult(Long examId,Long questionId,String currentTime){
        return Result.success(userQuestionService.exeResult(examId,questionId,currentTime));
    }
}
